#include <bits/stdc++.h>
using namespace std;
#define int long long
#define test cerr<<"miaoyu2022 cai\n"
const int siz=1e6+10;
int a[siz],v[siz],d[siz],tr[siz],p[siz],t,n,m,l,k,cnt=0;
struct chao{
    int l,r;
}c[siz];
bool cmp(chao _a,chao _b){return _a.l<_b.l;}
bool operator>(chao _a,chao _b){return _a.r>_b.r;}
void add(int x,int y)
{
    for(;x<=l;x+=x&-x)
        tr[x]+=y;
}
int sum(int x)
{
    if(x<=0) return 0;
    int res=0;
    for(;x;x-=x&-x)
        res+=tr[x];
    return res;
}
int abss(int x)
{
    if(x>0) return x;
    return -x;
}
signed main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin.tie(0),cout.tie(0);
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--)
    {
        memset(tr,0,sizeof tr);
        cnt=0;
        cin>>n>>m>>l>>k;
        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++)
        {
            cin>>p[i],add(p[i],1);
        }
        sort(p+1,p+m+1);
        for(int i=1;i<=n;i++)
        {
            int num=cnt;
            if(!a[i])
            {
                if(v[i]>k&&sum(l)-sum(d[i]-1)>=1) c[++cnt].l=d[i],c[cnt].r=l;
            }
            else if(a[i]>0)
            {
                int rig=d[i]+(int)(k*k-v[i]*v[i])/(2*a[i]);
                rig++;
                if(rig<d[i]) rig=d[i];
                else if(rig>l) continue;
                int le=rig,re=l;
                if(le<=re&&sum(re)-sum(le-1)>=1)
                    c[++cnt].l=le,c[cnt].r=re;
            }
            else
            {
                if(v[i]<=k) continue;
                int rig=d[i]+(int)(1ll*k*k-1ll*v[i]*v[i])/(2*a[i]);
                if((abss(1ll*k*k-1ll*v[i]*v[i])%abss(2ll*a[i]))==0) rig--;
                if(rig<d[i]) continue;
                else if(rig>l) rig=l;
                int le=d[i],re=rig;
                if(le<=re&&sum(re)-sum(le-1)>=1)
                    c[++cnt].l=le,c[cnt].r=re;
            }
        }
        cout<<cnt<<" ";
        sort(c+1,c+cnt+1,cmp);
        int j=1,ans=0;
        p[m+1]=2e9+10;
        int mn=2e9;
        for(int i=1;i<=m;i++)
        {
            while(j<=cnt&&c[j].l<=p[i])
                mn=min(mn,c[j++].r);
            if(mn!=2e9&&mn<p[i+1])
                ans++,mn=2e9;
        }
        cout<<(m-ans)<<"\n";
    }
    return 0;
}
